<template>
  <div class="news-list">
    <van-nav-bar title="新闻资讯" left-text="返回" left-arrow @click-left="$router.go(-1)" class="fixed-top"/>
    <ul>
      <li v-for="item in NewsMessage" :key="item.id" @click="handlejump(item.id)">
        <div class="news-item">
          <img :src="item.img_url" alt>
          <div class="content">
            <p class="content-title">{{item.title}}</p>
            <p class="content-info">
              <span class="content-time">{{item.add_time | dateFormat}}</span>
              <span class="content-click">有{{item.click}}条浏览</span>
            </p>
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { getNewsList } from '@/api'
export default {
  data () {
    return {
      NewsMessage: []
    }
  },
  created () {
    this.initNewsList()
  },
  methods: {
    initNewsList () {
      getNewsList().then(res => {
        // console.log(res)
        this.NewsMessage = res.data.message
        // console.log(this.NewsMessage)
      })
    },
    handlejump (newsid) {
      this.$router.push({ name: 'newsdetail', params: { id: newsid } })
    }
  }
}
</script>

<style lang="scss" scoped>
  .news-list {
    .fixed-top {
      width: 100%;
      position: fixed;
      top: 0;
    }
    ul {
      margin-top: 46px;
      li {
        padding: 5px;
      }
    }

    .news-item {
      display: flex;
      justify-content: space-between;
      align-items: center;

      img {
        width: 100px;
        height: 50px;
        margin-right: 10px;
        flex: 1;
      }

      .content {
        width: 250px;
        flex: 2;
        .content-title {
          font-size: 14px;
          font-weight: bold;
        }

        .content-info {
          display: flex;
          justify-content: space-between;
          width: 100%;
          color: #26a2ff;
          font-size: 12px;
        }
      }
    }
  }
</style>
